console.log("作业1：");
var str =
      `
        fjskfjsl fjkdsjfkls fjklsfjlsd127.0.0.1fjksldfjafjio
        jfk192.168.1.101sljfs fsdjfkldsfjsklfsklffjoijfoiafa
        sfjs fed jfjf jf sdjfsi jfi jafis function dd ( ) { }a
        fjsdiajf iosa function abc(){} jfisjad fjsaiofjaoissfa
        ddedfds
      `
console.log("初始字符串如下：");
console.log(str);

var str_rx = /\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}/g;
var str_rx2 = /(function\s+[a-zA-Z\_\$][\w\_\$]*\s*\(\s*\)\s*\{\s*\})/g;
console.log("字符串中匹配的IP为：");

//方法1---成功，结果为二元字符串数组
let result = str.match(str_rx);
console.log(result);

console.log("字符串中匹配的函数为：");
let result2 = str.match(str_rx2);
console.log(result2);

//方法2---成功，结果为两个字符串和null
// console.log("字符串中匹配的IP为：");
// let result;
// do{
//   result = str_rx.exec(str);
//   console.log(result && result[0])
// }while(result);
//
// console.log("字符串中匹配的函数为：");
// let result2;
// do{
//   result2 = str_rx2.exec(str);
//   console.log(result2 && result2[0])
// }while(result2);
